package view.swing;

import static util.Strings.STR_PLAY;
import static util.Strings.STR_SKIP;
import static util.Strings.STR_SWAP;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;

import controller.ActionController;

@SuppressWarnings("serial")
public class ButtonsPanel extends JPanel implements ActionListener {

    private JButton skipButton = new JButton(STR_SKIP);
    private JButton swapButton = new JButton(STR_SWAP);
    private JButton playButton = new JButton(STR_PLAY);
    private ActionController controller;

    public ButtonsPanel(ActionController controller) {
        super();
        this.controller = controller;
        // Construct a GridLayout with 2 columns and an unspecified number of
        // rows.
        GridLayout layout = new GridLayout(1, 0);
        layout.setHgap(1);
        setLayout(layout);
        skipButton.addActionListener(this);
        add(skipButton);
        swapButton.addActionListener(this);
        add(swapButton);
        playButton.addActionListener(this);
        add(playButton);

    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource().equals(skipButton)) {
            controller.skipTurn();
        } else if (e.getSource().equals(swapButton)) {
            controller.swap();
        } else if (e.getSource().equals(playButton)) {

            controller.playTurn();
        }
    }
}
